export default {
  data() {
    return {
      maritalStatus: false, //选择婚姻状态
      mStitle: '请选择', //婚姻状态title
      workingConditions: false, //选择工作状况
      wCtitle: '请选择', //工作状况title
      educationalLevel: false, //选择教育水平
      eltitle: '请选择', //教育水平title
      housingSituation: false, //选择住房状况
      hStitle: '请选择', //住房状况title
      isAgree: true, //false我同意选择  true未选择
      mSid: '', //婚姻状态
      wCid: '', //工作状况
      elid: '', //教育水平
      hSid: '', //住房状况
      namenaq: '', //姓名
      mobiles: '', //电话
      maritalist: [{
        name: '未婚',
        check: false,
        id: 0
      },
      {
        name: '已婚',
        check: false,
        id: 1
      },
      {
        name: '离婚',
        check: false,
        id: 2
      },
      {
        name: '丧偶',
        check: false,
        id: 3
      }
      ],
      worKlist: [{
        name: '自由职业',
        check: false,
        id: 0
      },
      {
        name: '个体工商户',
        check: false,
        id: 1
      },
      {
        name: '民营企业',
        check: false,
        id: 2
      },
      {
        name: '政府机关/事业单位',
        check: false,
        id: 3
      },
      {
        name: '三资企业',
        check: false,
        id: 4
      },
      {
        name: '国企央企/大型股份制公司',
        check: false,
        id: 5
      }
      ],
      eLlist: [{
        name: '初中',
        check: false,
        id: 0
      },
      {
        name: '高中',
        check: false,
        id: 1
      },
      {
        name: '技术职业学校',
        check: false,
        id: 2
      },
      {
        name: '大学专科',
        check: false,
        id: 3
      },
      {
        name: '大学本科',
        check: false,
        id: 4
      },
      {
        name: '研究生及以上',
        check: false,
        id: 5
      },
      {
        name: '其他',
        check: false,
        id: 6
      }
      ],
      houSlist: [{
        name: '租房',
        check: false,
        id: 0
      },
      {
        name: '亲属住房',
        check: false,
        id: 1
      },
      {
        name: '全款',
        check: false,
        id: 2
      },
      {
        name: '商业按揭房',
        check: false,
        id: 3
      },
      {
        name: '公积金按揭房',
        check: false,
        id: 4
      },
      {
        name: '自建房',
        check: false,
        id: 5
      },
      {
        name: '单位住房',
        check: false,
        id: 6
      }
      ],
      showPopup: false, //弹框显隐
      success: false, //提交成功
    }
  },
  onLoad(carids) {
    this.cardid = carids.cartyid
    this.panduanname()
  },
  methods: {
    // 客服电话
    onNavigationBarButtonTap(e) {
      uni.makePhoneCall({
        phoneNumber: this.$store.state.serviceNumber.number
      })
    },
    // 在缓存中取参数
    panduanname() {
      const value = uni.getStorageSync('Ztc_C_USER_INFO')
      if (value) {
        this.namenaq = value.trueName
        this.mobiles = value.mobile
      }
    },
    //下一步
    nextStep() {
      // 判断是否勾选协议
      if (this.isAgree) {
        // this.showPopup = true
        uni.showToast({
          icon: 'none',
          title: '请先阅读并同意购车协议'
        })
      } else {
        this.AddPersonalData()
      }
    },
    gouserAgreementPage() {
      // this.showPopup = true
      uni.navigateTo({
        url: '/pages_logins/agCarpur/agCarpur'
      })
    },
    //判断身份证上传接口
    async AddPersonalData() {
      if (this.mSid === '') {
        this.$refs.uToast.show({
          title: '请选择婚姻状态',
          type: 'warning',
          url: '/pages/user/index'
        })
        return
      } else if (this.wCid === '') {
        this.$refs.uToast.show({
          title: '请选择工作状态',
          type: 'warning',
          url: '/pages/user/index'
        })
        return
      } else if (this.elid === '') {
        this.$refs.uToast.show({
          title: '请选择教育水平',
          type: 'warning',
          url: '/pages/user/index'
        })
        return
      } else if (this.hSid === '') {
        this.$refs.uToast.show({
          title: '请选择住房状况',
          type: 'warning',
          url: '/pages/user/index'
        })
        return
      }
      try {
        const res = await this.$api.commodity.AddPersonalData({
          order_Buy_Car_Id: this.cardid, //购车订单外键Id
          name: this.namenaq, //姓名
          phone: this.mobiles, //联系电话
          marital_Status: this.mSid, //婚姻
          work_Status: this.wCid, //工作
          housing_Status: this.elid, //住房
          education_Level: this.hSid //教育
        })
        if (res.code === 200) {
          this.success = true
        }

      } catch (err) {}
    },
    // 查看申请，返回首页
    shenclick(type) {
      if (type) {
        uni.switchTab({
          url: '/pages/index/index'
        })
      } else {
        uni.navigateTo({
          url: '/pages_order/buy_order/buy_order?type=0'
        })
      }
    },
    //勾选免责
    Agree() {
      this.isAgree = !(this.isAgree)
    },
    //同意免责
    agreepopup(type) { //type 0同意
      if (type === 0) {
        this.isAgree = false
        this.showPopup = false //关闭免责弹框
      } else {
        this.isAgree = true
        this.showPopup = false //关闭免责弹框
      }
    },

    //婚姻状况
    maritSclick(items, type) {
      let listbox = [] //暂存赋值
      this.mStitle = items.name
      this.mSid = items.id
      this.maritalist.forEach((item, i) => {
        if (i === type) {
          if (item.check === false) {
            item.check = true
          } else {}
        } else {
          item.check = false
        }
        listbox.push(item)
      })
      this.maritalist = listbox
      this.maritalStatus = false
    },
    //工作状况
    workclick(items, type) {
      let listbox = [] //暂存赋值
      this.wCtitle = items.name
      this.wCid = items.id
      this.worKlist.forEach((item, i) => {
        if (i === type) {
          if (item.check === false) {
            item.check = true
          } else {}
        } else {
          item.check = false
        }
        listbox.push(item)
      })
      this.worKlist = listbox
      this.workingConditions = false
    },
    //教育水平
    elEclick(items, type) {
      let listbox = [] //暂存赋值
      this.eltitle = items.name
      this.elid = items.id
      this.eLlist.forEach((item, i) => {
        if (i === type) {
          if (item.check === false) {
            item.check = true
          } else {}
        } else {
          item.check = false
        }
        listbox.push(item)
      })
      this.eLlist = listbox
      this.educationalLevel = false
    },
    //住房状况
    housClick(items, type) {
      let listbox = [] //暂存赋值
      this.hStitle = items.name
      this.hSid = items.id
      this.houSlist.forEach((item, i) => {
        if (i === type) {
          if (item.check === false) {
            item.check = true
          } else {}
        } else {
          item.check = false
        }
        listbox.push(item)
      })
      this.houSlist = listbox
      this.housingSituation = false
    },
  }
}
